package com.stefanini.pe.bbva.bp.in.report;

import java.awt.Color;

import net.sf.jasperreports.engine.JRChart;
import net.sf.jasperreports.engine.JRChartCustomizer;

import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.renderer.category.BarRenderer;

/**
 * @author Teodor Danciu (teodord@users.sourceforge.net)
 * @version $Id:BarChartCustomizer.java 2317 2008-08-27 09:06:42Z teodord $
 */
public class BarChartCustomizer implements JRChartCustomizer {
	private Number tickUnits = 0;

	public void customize(JFreeChart chart, JRChart jasperChart) {
		BarRenderer renderer = (BarRenderer) chart.getCategoryPlot()
				.getRenderer();
		renderer.setSeriesPaint(0, Color.red);
		renderer.setSeriesPaint(1, Color.blue);
		renderer.setMaximumBarWidth(10);
		CategoryPlot plot = chart.getCategoryPlot();
		NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
		rangeAxis.setStandardTickUnits(rangeAxis.createIntegerTickUnits());
		rangeAxis.setAutoRangeIncludesZero(true);
		CategoryAxis axis = plot.getDomainAxis();
		axis.setLowerMargin(0.02); // two percent
		axis.setCategoryMargin(0.05); // ten percent
		axis.setUpperMargin(0.02); // two percent
	}
}
